package znbkTestPaperBj.presenter;

import android.util.Log;

import com.example.lancooznbk.view.base.ILoadPaperView;
import com.lancoo.rxretrofitlibrary.http.HttpManager;
import com.lancoo.rxretrofitlibrary.listener.HttpOnNextListener;

import znbkListBj.INotePresenter;
import znbkListBj.entity.NoteListEntity;
import znbkTestPaperBj.activity.NotePaperActivity;
import znbkTestPaperBj.api.NotePaperApi;
import znbkTestPaperBj.entity.NotePaperEntity;

/**
 * Created by Administrator on 2018\3\22 0022.
 */

public class NotePaperPresenter implements INotePresenter {

    private ILoadPaperView view;

    public NotePaperPresenter(ILoadPaperView view) {
        this.view = (ILoadPaperView) view;
    }

    @Override
    public void getData(boolean isShowLoading) {
        if (isShowLoading) view.showLoading();

        HttpOnNextListener<NotePaperEntity> httpOnNextListener = new HttpOnNextListener<NotePaperEntity>() {
            @Override
            public void onNext(NotePaperEntity notePaperEntity) {


                if (notePaperEntity.getModelTKQue() != null) {
                    view.hideLoading();
                    view.loadPaperData(notePaperEntity);
                }else {
                    view.showNoData("暂无内容");
                }
            }


            @Override
            public void onError(Throwable e) {
                super.onError(e);
                view.showNetError();
            }

            @Override
            public void onComplete() {
                super.onComplete();
                Log.d("TML","end: "+System.currentTimeMillis());
            }
        };

        NotePaperApi api = new NotePaperApi(httpOnNextListener, (NotePaperActivity)view);

        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(api);
    }

    @Override
    public void getMoreData() {
        getData(false);
    }


    @Override
    public void searchFavouriteItem(String str) {

    }

    @Override
    public void openFavoriteItemDetail(int position, NoteListEntity.NoteBean noteBean) {

    }

    @Override
    public void delItemFavourite(int position, NoteListEntity.NoteBean noteBean) {

    }
}